<?php 
// Header 
$this->set('title_for_layout', __("Danh sách thành viên", true));

$this->left_menu = 'menu/manage_user';
echo $this->Html->css('/users/css/index')
?>

<h2 class='page_heading'><?php __("Danh sách thành viên")?></h2>
<?php echo $session->flash()?>

<div class="buttons atbottom">
	<ul>
		<li><a href="javascript:void(0)" class="cancel delete_users"><?php __("Xóa")?></a></li>
		<li><a href="<?php echo $html->url(array('plugin' => 'users', 'controller' => 'manage_users', 'action' => 'add'))?>" class="new"><?php __("Thêm mới")?></a></li>
	</ul>
</div>
<!-- buttons.end -->

<!-- table -->
<div class="table">
	<table cellpadding="0" cellspacing="0" id='users_list'>
		<thead>
			<tr>
				<th width='20'><?php echo $paginator->sort(__('#', true), 'id') ?></th>
				<th width='20'><input type="checkbox" id='checkbox-control' control='index'/></th>
				<th width='180'><?php echo $paginator->sort(__('Tên đăng nhập', true), 'username') ?></th>
				<th><?php echo $paginator->sort(__('Tên đầy đủ', true), 'first_name') ?></th>
				<th width='160'><?php echo $paginator->sort(__('Email', true), 'email') ?></th>
				<th width='120'><?php echo $paginator->sort(__('Phone', true), 'phone') ?></th>
				<th width='160'><a><?php echo __('Chức năng', true) ?></a></th>
			</tr>
		</thead>
		<tbody>
			<?php if(empty($users)):?>
			<tr class="row1">
				<td colspan="8" align="center" style="font-weight:bold"><?php echo __("Chưa có dữ liệu.");?></td>
			</tr>
			<?php
			endif;
				$max = $paginator->params['paging']['User']['defaults']['limit'];
				$page = $paginator->params['paging']['User']['page'];
				$start = ($page - 1) * $max;
				$i=0;
				$class = 'altrow';
				$room_type_list = array();
				foreach($users as $user):
					$class = $class == "" ? "class='odd'" : "";
					$page_id = $user['User']['id'];
					//$class = "row".($i%2)?"0":"1";
					$i++;
			?>
			<tr <?php echo $class?> page_id="<?php echo $page_id?>">
				<td><?php echo ($start + $i)?></td>
				<td class="center"><input type="checkbox" class='index' name='checkbox_index[]' value='<?php echo $page_id?>'/></td>
				<td><?php echo $user['User']['username']; ?></td>
				<td><?php echo $user['User']['first_name']. ' ' . $user['User']['last_name']; ?></td>
				<td><?php echo $user['User']['email'];?></td>
				<td><?php echo $user['User']['phone'];?></td>
				<td class='actions'>
					<div class="functions">
						<div class="header"><h4><?php __("Chức năng");?></h4></div>
						<ul>
							<li><a href="<?php echo $html->url(array('plugin' => 'users', 'controller' => 'manage_users', 'action'=>'edit', $user['User']['id']))?>" class="edit"><?php __("Chỉnh sửa")?></a></li>
							<li><a id_change="<?php echo $user['User']['id']?>" href="<?php echo $html->url(array('plugin' => 'users', 'controller'=>$this->params['controller'], 'action'=>'change_pass', $user['User']['id']))?>" class="key change_password"><?php __("Đổi mật khẩu")?></a></li>
							<li><a href="<?php echo $html->url(array('plugin' => 'users', 'controller' => 'manage_users', 'action'=>'delete', $user['User']['id']))?>" class="delete delete_page" onclick="return confirm('<?php __("Bạn có thật sự muốn xóa thành viên này?")?>')"><?php __("Xóa")?></a></li>
						</ul>
					</div>
				</td>
			</tr>
			<?php endforeach;?>
		</tbody>
	</table>
</div>
<!-- table.end -->

<!-- paging -->
<div class="paging-wrapper">
<?php echo $this->element('pagination/pagination', array('model' => 'User'));?>
</div>
<!-- paging.end -->

<!-- buttons -->
<div class="buttons atbottom">
	<ul>
		<li><a href="javascript:void(0)" class="cancel delete_users"><?php __("Xóa")?></a></li>
		<li><a href="<?php echo $html->url(array('plugin' => 'users', 'controller' => 'manage_users', 'action' => 'add'))?>" class="new"><?php __("Thêm mới")?></a></li>
	</ul>
</div>
<!-- buttons.end -->

<!-- Form cho sự kiện xóa -->
<form style="display:none" id='mass_delete' method='post' 
action="<?php echo $html->url(array('plugin' => 'users', 'controller' => 'manage_users', 'action' => 'mass_delete'))?>"
></form>
<div id='change_pass_dialog' title="<?php __("Thay đổi mật khẩu người dùng")?>" class='cake_form'>
	<?php 
		echo $form->create("User", array('url'	=>	array(
				"plugin"		=> "users",
				"controller"	=> 'manage_users', 
				"action"		=> "change_pass"
			),
			"id"	=> "changeUserPassword"
		));
		?>
	<fieldset class="form">
	
	<?php 
		echo $form->input('id', array('type'=>'hidden', 'id' => 'changeID'));
		echo $form->input('new_password',array( 'label' => __("Mật khẩu mới:", true), 'type'=>'password'));
		echo $form->input('re_new_password',array( 'label' => __("Nhập lại mật khẩu:", true), 'type'=>'password'));
		?>
	<div align='center' class='submit'>
		<input type='submit' name='btnSubmit' value='<?php __("Đổi mật khẩu")?>' class='button'/>
	</div>
	</fieldset>
	<?php 
		echo $form->end(); 	
	?>
</div>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
	$('div.buttons a.delete_users').click(function() {
		if (confirm("<?php __("Bạn có thật sự muốn xóa những thành viên đã được đánh dấu?")?>")) {
			var checkboxes = $('input[type="checkbox"].index');
			$('form#mass_delete').append(checkboxes).submit();
		}
	});
});
</script>
<?php echo $this->Html->script('jquery.form')?>
<?php echo $this->Html->script('/users/js/index')?>
<?php echo $this->Html->script('index_checkboxes')?>